package me.zhengjie.modules.system.service.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.allwees.bs.core.modelbase.branch.BranchUser;
import com.allwees.bs.core.modelbase.branch.EBranchType;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author Zheng Jie
 * @date 2018-11-23
 */
@Data
public class UserDto implements BranchUser, Serializable {
    private static final long serialVersionUID = -3459052630482787709L;
//    @ApiModelProperty(hidden = true)
    private Long id;

    private String uuid;

    private String username;

    private String nickName;

    private String sex;

    private String avatar;

    private String email;

    private String phone;

    private Boolean enabled;

    @JsonIgnore
    private String password;

    private Date lastPasswordResetTime;

//    @ApiModelProperty(hidden = true)
    private Set<RoleSmallDto> roles;

//    @ApiModelProperty(hidden = true)
    private JobSmallDto job;

    private DeptSmallDto dept;

    private Long deptId;

    private EBranchType branchType;

    private String branchUuid;

	@Override
	public boolean isEnabled() {
		return getEnabled() != null && getEnabled();
	}

    private Timestamp createTime;

    private Boolean registered;

    private Boolean shopCreated;

    @Override
	public String[] getRoleNames() {
        if(CollectionUtils.isEmpty(getRoles())){
            return new String[0];
        }
    	List<String> roleNames = new ArrayList<>();
    	for(RoleSmallDto role : getRoles()) {
    		roleNames.add(role.getName());
    	}
    	return roleNames.toArray(new String[0]);
    }
}
